<?php
namespace app\reserve\validate;
use think\Validate;
use think\Db;
/**
 * Class CashValidate
 * @package app\api\validate
 * @author zhenHong~
 * 商户验证类
 */
class WashcashValidate extends Validate{
    protected $rule = [
        'washid'          => ['require','number'],
        'account'     => ['require','regex' => '^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$','checkAccountUnique'],
        'contactnum'  => ['require'],
        'password'    => ['regex' => '/^[a-zA-Z0-9]{6,18}$/'],
        'province'    => ['require'],
        'city'        => ['require'],
        'area'        => ['require'],
        'legal_person'=> ['require'],
        'id_number'   => ['require','regex' => '/(^\d{15}$)|(^\d{17}([0-9]|X)$)/'],
        'email'       => ['email'],
        'name'        => ['require'],
        'washid'      => ['integer','require'],
        'pagenum'     => ['integer'],
        'lon'         => ['between:0,180'],
        'lat'         => ['between:0,90'],
        'a_id'        => ['require','number'],
        'code'        => ['require','number'],
        'attestation_id'=> ['require'],
    ];

    protected $message = [
        'account.require' => '登陆账号不能为空',
        'account.regex' => '登录手机号格式不正确',
        'account.checkAccountUnique' => '商户已注册',
        'contactnum' => '商户联系电话不能为空',
        'password' => '密码由6~18字母加数字组成',
        'province' => '请选择省份',
        'city'     => '请选择城市',
        'area'     => '请选择地区',
        'legal_person' => '请填写法人姓名',
        'id_number' => '身份证号码格式不正确',
        'email'     => '邮箱格式不正确',
        'name'      => '商户名称不能为空',
        'wash'      => '参数格式错误wash',
        'pagenum'   => '参数格式错误pagenum',
        'lon'       => '经度参数错误',
        'lat'       => '纬度参数错误',
        'a_id'      => '商户id不能为空',
        'washid'        => '洗车商户id不能为空',
        'code'      => 'code不能为空',
        'attestation_id' => '认证id不能为空',
    ];

    protected $scene = [
        //添加洗车商户
        'addWashcash' => ['account','contactnum','province','city','area','legal_person','id_number','email','name','lon','lat','a_id'],
        //删除洗车商户
        'deletWashcash' => ['washid'],
        // 修改洗车商户
        'editWashcash'  => ['washid'],
        // 洗车商户登录
        'washlogin' => ['account'=>['require','regex' => '^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$'],'password'],
        //查询洗车商户
        'selectWashcash' => ['pagenum'=>'require'],
        //确认洗车订单
        'makesureOrder' => ['washid'=>'require','code'=>'require'],
        // 修改密码
        'editPass'      => ['password'],

        // 洗车商户添加认证
        'addAttestation'    => ['washid','attestation_id']
    ];

    /**
     * @param $value
     * @return bool
     * 校验账号的唯一性
     */
    protected function checkAccountUnique($value){
        $result = Db::name('washcash')
            ->where('account',$value)
            ->value('account');
        return $result ? false : true;
    }
}